<?php
/**
 * Created by PhpStorm.
 * User: luzy
 * Date: 2018/5/18
 * Time: 下午3:15
 */

class Share extends Base_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->model('kdtsalesman_model');
    }

    public function getRankList()
    {
        $post = $this->input->post();
        if (!isset($post['pagesize'])||!is_numeric($post['pagesize'])) $limit=20;
        else $limit = (int)$post['pagesize'];

        if (isset($post['pageno'])&&is_numeric($post['pageno'])) $offset = ((int)$post['pageno']-1)*$limit;
        else $offset = 0;

        $res=$this->kdtsalesman_model->getShareRankList($offset,$limit,time());
        $this->success($res);
    }

    public function getLastDayRankList()
    {
        $post = $this->input->post();
        if (!isset($post['pagesize'])||!is_numeric($post['pagesize'])) $limit=20;
        else $limit = (int)$post['pagesize'];

        if (isset($post['pageno'])&&is_numeric($post['pageno'])) $offset = ((int)$post['pageno']-1)*$limit;
        else $offset = 0;

        $time = time()-24*3600;
        $res=$this->kdtsalesman_model->getShareRankList($offset,$limit,$time);
        $this->success($res);
    }

    public function getRemainMoney()
    {
        $sls=$this->input->get('sls');
        if (!isset($sls)||empty($sls)) $this->error();

        $this->load->model('kdtsalesman_model');
        $res = $this->kdtsalesman_model->getShareRemainMoney($sls);

        $this->success($res);
    }
    //提现申请
    public function demandMoney()
    {
        $sls=$this->input->get('sls');
        $money=$this->input->get('money');//*100后的金额
        if (!isset($sls)||empty($sls)||!isset($money)||!is_numeric($money)) $this->error();

        $money=(int)$money;
        $this->load->model('kdtsalesman_model');
        $res = $this->kdtsalesman_model->demandShareMoney($sls,$money);
        $this->success($res);
    }

    public function getMoneyRecord()
    {
        $sls=$this->input->get('sls');
        if (!isset($sls)||empty($sls)) $this->error();

        $this->load->model('kdtsalesman_model');
        $res = $this->kdtsalesman_model->getMoneyRecord($sls);
        $this->success($res);
    }

    public function getShareArticleVistor()
    {
        $post=$this->input->post();
        if (!isset($post['sls'])||empty($post['sls'])) $this->error('param error');

        if (!isset($post['pagesize'])||!is_numeric($post['pagesize'])) $limit=20;
        else $limit = (int)$post['pagesize'];

        if (isset($post['pageno'])&&is_numeric($post['pageno'])) $offset = ((int)$post['pageno']-1)*$limit;
        else $offset = 0;

        $this->load->model('kdtsalesman_model');
        $res = $this->kdtsalesman_model->getShareArticleVistor($post['sls'],$limit,$offset);

        $this->success($res);
    }

    public function getSharePostScanner()
    {
        $post=$this->input->post();
        if (!isset($post['sls'])||empty($post['sls'])) $this->error('param error');

        if (!isset($post['pagesize'])||!is_numeric($post['pagesize'])) $limit=20;
        else $limit = (int)$post['pagesize'];

        if (isset($post['pageno'])&&is_numeric($post['pageno'])) $offset = ((int)$post['pageno']-1)*$limit;
        else $offset = 0;

        $this->load->model('kdtsalesman_model');
        $res = $this->kdtsalesman_model->getSharePostScanner($post['sls'],$limit,$offset);

        $this->success($res);
    }
}